package cn.com.dstz.taglib;

import java.util.Map;

import javax.servlet.jsp.JspException;

import org.apache.commons.lang.StringUtils;

public class ChildPermissionsFilter extends PermissionsFilter{
	
	private static final long serialVersionUID = 1L;

	private String queryParams;
	private Boolean javascript;
	

	@Override
	public int doEndTag( ) throws JspException {
		return super.doEndTag( );
	}

	@Override
	public int doStartTag( ) throws JspException {
		return super.doStartTag( );
	}

	@Override
	public void release( ) {
		super.release( );
		queryParams = null;
		javascript = null;
	}
	
	@Override
	public String getHref( Map< String, Object > purview ) {
		String href = "";
		Object permissionName = "[&nbsp;" +  ( StringUtils.isNotBlank( name ) ? name : purview.get( "name" )) + "&nbsp;]" ;
		
		if( javascript != null && javascript ){
			 href += "<a href=\"javascript:;\" onclick=\"" + queryParams + "\">" + permissionName + "</a>&nbsp;&nbsp;";
			 return href;
		}
		
		return "<a href=\"" + getUrlWithServletContextPath( ) + queryParams + "\" target=\"" + getTarget( ) + "\">" + permissionName+ "</a>&nbsp;&nbsp;";
	}

	@Override
	public String responseURL( Map< String, Object > purview ) {
		return getHref( purview );
	}

	public String getQueryParams( ) {
		return queryParams;
	}

	public void setQueryParams( String queryParams ) {
		this.queryParams = queryParams;
	}

	public Boolean getJavascript( ) {
		return javascript;
	}

	public void setJavascript( Boolean javascript ) {
		this.javascript = javascript;
	}
	
}
